home *** CD-ROM | disk | FTP | other *** search
- #include "flame.h"
-
- #define kDefaultRes 0x00480000
-
-
- FlamePtr FlamesDialogBox(CTabHandle fireColors, PixMapPtr thePix,
- short *odds, short *max, short *min, Boolean *fuzz, short *takeaway);
- void ShowNum(long theLong);
- long GetNum(short itemNum, DialogPtr theDialog);
- void SetNum(short itemNum, DialogPtr theDialog, int tempNum);
- void ToggleCheckMark(int itemNum, DialogPtr theDialog);
- Boolean GetCheckMark(int itemNum, DialogPtr theDialog);
- OSErr SetUpPixMap(short depth,
- Rect *bounds,
- CTabHandle colors,
- PixMapHandle thePixMap);
-
- void main(void)
- {
- WindowPtr outWin;
- PixMapPtr firePlace;
- OSErr theErr;
- Rect destRect;
- CTabHandle fireColors,
- systemColors;
- FlamePtr fire;
- Rect tempRect;
- long start,
- end,
- count = 0;
- short i;
- short odds, lenght, takeAway, max, min;
- Boolean fuzz;
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- qd.randSeed = TickCount();
- FlushEvents(everyEvent,0);
- MaxApplZone();
- MoreMasters();
- MoreMasters();
-
- outWin = GetNewCWindow(128, nil, (WindowPtr)-1);
- destRect = outWin->portRect;
-
-
- fireColors = (CTabHandle)GetResource('clut', 128);
- HLock((Handle)fireColors);
-
- theErr = SetUpPixMap(8, &destRect, fireColors, &firePlace);
-
- fire = FlamesDialogBox(fireColors, firePlace, &odds, &max, &min, &fuzz, &takeAway);
-
- if (theErr != noErr)
- {
- ShowNum(theErr);
- CloseWindow(outWin);
- ExitToShell();
- }
-
- ReleaseResource((Handle)fireColors);
-
- start = TickCount();
- do{
- count++;
- SetUpBurn(odds, max, min, fire);
- Burn(fire, takeAway, fuzz);
- CopyFlame(0,0,fire, firePlace);
- CopyBits((BitMapPtr)firePlace,
- &((GrafPtr)outWin)->portBits,
- &destRect, &destRect,
- srcCopy, nil);
- }while(!Button());
- end = TickCount();
-
- ShowNum(((double)count/(end - start))*60);
- CloseWindow(outWin);
- KillFlames(&fire);
- }
-
- void ShowNum(long theLong)
- {
- DialogPtr theDialog;
- GrafPtr oldPort;
- short item;
-
- theDialog = GetNewDialog(128, nil, (WindowPtr)-1);
- GetPort(&(GrafPtr)oldPort);
- ShowWindow(theDialog);
- SelectWindow(theDialog);
- SetPort(theDialog);
- SetNum(3, theDialog, theLong);
- do{
- ModalDialog(nil, &item);
- }while(item != 1);
- CloseDialog(theDialog);
- SetPort(oldPort);
- }
-
- FlamePtr FlamesDialogBox(CTabHandle fireColors, PixMapPtr thePix,
- short *odds, short *max, short *min, Boolean *fuzz, short *takeaway)
- {
- DialogPtr theDialog;
- short item;
- FlamePtr tempFire;
-
- theDialog = GetNewDialog(129, nil, (WindowPtr)-1);
- ShowWindow(theDialog);
- SelectWindow(theDialog);
- SetPort(theDialog);
-
- do{
- ModalDialog(nil, &item);
- if (item == 7)
- ToggleCheckMark(7, theDialog);
- if (item == 6)
- ToggleCheckMark(6, theDialog);
- }while(item != 1);
-
- if(GetCheckMark(7, theDialog))
- SetUpFlames(fireColors, thePix->pmTable, &thePix->bounds, lowRes2, &tempFire);
- else
- SetUpFlames(fireColors, thePix->pmTable, &thePix->bounds, noSpeedUp, &tempFire);
-
- *odds = GetNum(2, theDialog);
- *max = GetNum(3, theDialog);
- *min = GetNum(4, theDialog);
- *fuzz = GetCheckMark(6, theDialog);
- *takeaway =GetNum(5, theDialog);
-
- CloseDialog(theDialog);
- return tempFire;
- }
-
- void SetNum(short itemNum, DialogPtr theDialog, int tempNum)
- {
- Handle dummyHandle;
- Rect dummyRect;
- short dummyType;
- unsigned char tempText[256];
-
- NumToString(tempNum, &tempText[0]);
-
- GetDialogItem(theDialog, itemNum, &dummyType, &dummyHandle, & dummyRect);
- SetDialogItemText(dummyHandle, tempText);
- }
-
-
- long GetNum(short itemNum, DialogPtr theDialog)
- {
- Handle dummyHandle;
- Rect dummyRect;
- short dummyType;
- unsigned char tempText[256];
- long tempNum;
-
- GetDialogItem(theDialog, itemNum, &dummyType, &dummyHandle, & dummyRect);
- GetDialogItemText(dummyHandle, tempText);
-
- StringToNum(tempText, &tempNum);
- return tempNum;
- }
-
- void ToggleCheckMark(int itemNum, DialogPtr theDialog)
- {
- Handle dummyHandle;
- Rect dummyRect;
- short dummyType,
- theValue;
-
- GetDialogItem(theDialog, itemNum, &dummyType, &dummyHandle, &dummyRect);
- theValue = GetControlValue((ControlHandle)dummyHandle);
- if (theValue == true)
- {
- SetControlValue((ControlHandle)dummyHandle, false);
- } else {
- SetControlValue((ControlHandle)dummyHandle, true);
- }
- }
-
- Boolean GetCheckMark(int itemNum, DialogPtr theDialog)
- {
- Handle dummyHandle;
- Rect dummyRect;
- short dummyType,
- theValue;
-
- GetDialogItem(theDialog, itemNum, &dummyType, &dummyHandle, & dummyRect);
- theValue = GetControlValue((ControlHandle)dummyHandle);
- if (theValue == true)
- {
- return true;
- } else {
- return false;
- }
- }
-
-
- OSErr SetUpPixMap(short depth,
- Rect *bounds,
- CTabHandle colors,
- PixMapHandle thePixMap)
- {
- CTabHandle newColors;
- Ptr offBaseAddr;
- OSErr error;
- short bytesPerRow;
-
- error = noErr;
- newColors = nil;
- offBaseAddr = nil;
-
- *thePixMap = (PixMapPtr) NewPtr(sizeof(PixMap));
- if (depth <= 8)
- {
- if (colors != nil)
- {
- newColors = colors;
- error = HandToHand((Handle *) &newColors);
- } else {
- /*asign system clut*/
- }
- } else {
- newColors = (CTabHandle)NewHandle(sizeof(ColorTable) - sizeof(CSpecArray));
- error = MemError();
- }
-
- if (error == noErr)
- {
- bytesPerRow = ((((long)depth *
- (long)(bounds->right - bounds->left)) + 15L) >> 4L) << 1L;
- offBaseAddr = NewPtrClear((unsigned long)bytesPerRow * (bounds->bottom - bounds->top));
- if (offBaseAddr != nil)
- {
- (**thePixMap).baseAddr = offBaseAddr;
- (**thePixMap).rowBytes = bytesPerRow | 0x8000;
- (**thePixMap).bounds = *bounds;
- (**thePixMap).pmVersion = 0;
- (**thePixMap).packType = 0;
- (**thePixMap).packSize = 0;
- (**thePixMap).hRes = kDefaultRes;
- (**thePixMap).vRes = kDefaultRes;
- (**thePixMap).pixelSize = depth;
- (**thePixMap).planeBytes = 0;
- (**thePixMap).pmReserved = 0;
- if (depth <=8)
- {
- (**thePixMap).pixelType = 0;
- (**thePixMap).cmpCount = 1;
- (**thePixMap).cmpSize = depth;
- (**thePixMap).pmTable = newColors;
- } else {
- (**thePixMap).pixelType = RGBDirect;
- (**thePixMap).cmpCount = 3;
- if (depth == 16)
- (**thePixMap).cmpSize = 5;
- else
- (**thePixMap).cmpSize = 8;
- (**newColors).ctSeed = 3 * (**thePixMap).cmpSize;
- (**newColors).ctFlags = 0;
- (**newColors).ctSize = 0;
- (**thePixMap).pmTable = newColors;
- }
- } else
- error = MemError();
- } else
- newColors = nil;
- if(error != noErr)
- {
- if (newColors != nil)
- DisposeCTable(newColors);
- }
- return error;
- }
-